home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 September / CHIP 1996 szeptember (CD07).zip / CHIP_CD07.ISO / sac / pack / vblha1.lzh / MAIN.FRM < prev    next >
Text File  |  1995-05-08  |  15KB  |  694 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    ClientHeight    =   4035
  4.    ClientLeft      =   375
  5.    ClientTop       =   1920
  6.    ClientWidth     =   8625
  7.    Height          =   4770
  8.    Left            =   315
  9.    LinkTopic       =   "Form2"
  10.    ScaleHeight     =   4035
  11.    ScaleWidth      =   8625
  12.    Top             =   1245
  13.    Width           =   8745
  14.    Begin PictureBox picStatus 
  15.       Align           =   2  'Align Bottom
  16.       BackColor       =   &H00C0C0C0&
  17.       Height          =   255
  18.       Left            =   0
  19.       ScaleHeight     =   225
  20.       ScaleWidth      =   8595
  21.       TabIndex        =   3
  22.       Top             =   3780
  23.       Width           =   8625
  24.       Begin TextBox txtMemo 
  25.          BackColor       =   &H00C0C0C0&
  26.          Height          =   285
  27.          Left            =   3840
  28.          TabIndex        =   9
  29.          Top             =   0
  30.          Width           =   1335
  31.       End
  32.       Begin TextBox txtFname 
  33.          BackColor       =   &H00C0C0C0&
  34.          Height          =   285
  35.          Left            =   2640
  36.          TabIndex        =   6
  37.          Top             =   0
  38.          Width           =   1215
  39.       End
  40.       Begin TextBox txtName 
  41.          BackColor       =   &H00C0C0C0&
  42.          Height          =   285
  43.          Left            =   1200
  44.          TabIndex        =   5
  45.          Top             =   0
  46.          Width           =   1455
  47.       End
  48.       Begin TextBox txtID 
  49.          BackColor       =   &H00C0C0C0&
  50.          Height          =   285
  51.          Left            =   120
  52.          TabIndex        =   4
  53.          Top             =   0
  54.          Width           =   1095
  55.       End
  56.    End
  57.    Begin ComboBox cboID 
  58.       Height          =   300
  59.       Left            =   1320
  60.       Style           =   2  'Dropdown List
  61.       TabIndex        =   2
  62.       Top             =   120
  63.       Width           =   1815
  64.    End
  65.    Begin PictureBox PicControl 
  66.       Align           =   1  'Align Top
  67.       BackColor       =   &H00C0C0C0&
  68.       FillColor       =   &H00FFFFFF&
  69.       Height          =   495
  70.       Left            =   0
  71.       ScaleHeight     =   465
  72.       ScaleWidth      =   8595
  73.       TabIndex        =   1
  74.       Top             =   0
  75.       Width           =   8625
  76.       Begin TextBox txtFrom 
  77.          Height          =   285
  78.          Left            =   5760
  79.          TabIndex        =   13
  80.          Top             =   120
  81.          Width           =   1215
  82.       End
  83.       Begin TextBox txtSub 
  84.          Height          =   285
  85.          Left            =   3600
  86.          TabIndex        =   11
  87.          Top             =   120
  88.          Width           =   1575
  89.       End
  90.       Begin OptionButton optMemo 
  91.          BackColor       =   &H00C0C0C0&
  92.          Caption         =   "&Memo"
  93.          FontBold        =   0   'False
  94.          FontItalic      =   0   'False
  95.          FontName        =   "Arial"
  96.          FontSize        =   8.25
  97.          FontStrikethru  =   0   'False
  98.          FontUnderline   =   0   'False
  99.          Height          =   255
  100.          Left            =   600
  101.          TabIndex        =   10
  102.          Top             =   0
  103.          Width           =   1095
  104.       End
  105.       Begin OptionButton optName 
  106.          BackColor       =   &H00C0C0C0&
  107.          Caption         =   "&Name"
  108.          FontBold        =   0   'False
  109.          FontItalic      =   0   'False
  110.          FontName        =   "Arial"
  111.          FontSize        =   8.25
  112.          FontStrikethru  =   0   'False
  113.          FontUnderline   =   0   'False
  114.          Height          =   255
  115.          Left            =   120
  116.          TabIndex        =   8
  117.          Top             =   240
  118.          Width           =   735
  119.       End
  120.       Begin OptionButton optID 
  121.          BackColor       =   &H00C0C0C0&
  122.          Caption         =   "&ID"
  123.          FontBold        =   0   'False
  124.          FontItalic      =   0   'False
  125.          FontName        =   "Arial"
  126.          FontSize        =   8.25
  127.          FontStrikethru  =   0   'False
  128.          FontUnderline   =   0   'False
  129.          Height          =   255
  130.          Left            =   120
  131.          TabIndex        =   7
  132.          Top             =   0
  133.          Width           =   495
  134.       End
  135.       Begin Label lblFrom 
  136.          BackColor       =   &H00C0C0C0&
  137.          Caption         =   "From:"
  138.          Height          =   255
  139.          Left            =   5280
  140.          TabIndex        =   14
  141.          Top             =   120
  142.          Width           =   495
  143.       End
  144.       Begin Label lblSub 
  145.          BackColor       =   &H00C0C0C0&
  146.          Caption         =   "Sub:"
  147.          Height          =   255
  148.          Left            =   3240
  149.          TabIndex        =   12
  150.          Top             =   120
  151.          Width           =   375
  152.       End
  153.    End
  154.    Begin TextBox txtWorkarea 
  155.       BorderStyle     =   0  'None
  156.       Height          =   1815
  157.       Left            =   0
  158.       MultiLine       =   -1  'True
  159.       ScrollBars      =   3  'Both
  160.       TabIndex        =   0
  161.       Top             =   480
  162.       Width           =   3375
  163.    End
  164.    Begin Menu mnuFile 
  165.       Caption         =   "&File"
  166.       Begin Menu mnuNew 
  167.          Caption         =   "&New"
  168.       End
  169.       Begin Menu mnuOpen 
  170.          Caption         =   "&Open"
  171.       End
  172.       Begin Menu mnuSave 
  173.          Caption         =   "&Save"
  174.       End
  175.       Begin Menu mnuClose 
  176.          Caption         =   "&Close"
  177.       End
  178.       Begin Menu mnuSep1 
  179.          Caption         =   "-"
  180.       End
  181.       Begin Menu mnuFDelete 
  182.          Caption         =   "&Delete"
  183.       End
  184.       Begin Menu mnuTrash 
  185.          Caption         =   "&Trash"
  186.       End
  187.       Begin Menu mnuSep2 
  188.          Caption         =   "-"
  189.       End
  190.       Begin Menu mnuExit 
  191.          Caption         =   "E&xit"
  192.       End
  193.    End
  194.    Begin Menu mnuEdit 
  195.       Caption         =   "&Edit"
  196.       Begin Menu mnuCut 
  197.          Caption         =   "Cu&t"
  198.       End
  199.       Begin Menu mnuCopy 
  200.          Caption         =   "&Copy"
  201.       End
  202.       Begin Menu mnuPaste 
  203.          Caption         =   "&Paste"
  204.       End
  205.       Begin Menu mnuDelete 
  206.          Caption         =   "&Delete"
  207.       End
  208.    End
  209.    Begin Menu mnuView 
  210.       Caption         =   "&View"
  211.    End
  212.    Begin Menu mnuOptions 
  213.       Caption         =   "&Options"
  214.    End
  215. End
  216. Option Explicit
  217.  
  218. Dim TotalRec As Long
  219.  
  220. Sub cboID_Click ()
  221.  
  222. 'Update status bar
  223. procStatusBar
  224.  
  225. End Sub
  226.  
  227. Sub Form_Activate ()
  228.  
  229. 'Update status bar
  230. procStatusBar
  231.  
  232. 'Set file name to default
  233. If workfile.fopen = "" Then
  234.  frmMain.Caption = txtFname.Text
  235. End If
  236.  
  237. End Sub
  238.  
  239. 'Copyright 1995 by Hitoshi Ozawa
  240. Sub Form_Load ()
  241.  
  242. ' Load the frmGetFile dialog box without displaying
  243. Load frmGetFile
  244.  
  245. 'Initialize the cboFileType combo box of the frmGetFile
  246. frmGetFile.cboFileType.AddItem "Text files (*.txt)"
  247. frmGetFile.cboFileType.AddItem "All files (*.*)"
  248. frmGetFile.cboFileType.AddItem "LHA files (*.LZH)"
  249. frmGetFile.cboFileType.ListIndex = 0
  250.  
  251. 'Initialize to ID selection
  252. optID.Value = True
  253.  
  254. 'Initialize ID combo list
  255. procGetID
  256.  
  257. End Sub
  258.  
  259. Sub Form_Resize ()
  260.  
  261. picControl.ScaleWidth = frmMain.ScaleWidth
  262.  
  263. txtWorkArea.Width = frmMain.ScaleWidth
  264. txtWorkArea.Height = frmMain.ScaleHeight - picControl.ScaleHeight - picStatus.ScaleHeight
  265.  
  266. End Sub
  267.  
  268. 'Copyright 1995 by Hitoshi Ozawa
  269. Sub mnuClose_Click ()
  270.  
  271. 'Clear text area
  272. txtWorkArea.Text = ""
  273. frmMain.Caption = ""
  274.  
  275. 'Reset filenames
  276. workfile.lopen = ""
  277. workfile.fopen = ""
  278.  
  279. 'Refresh frmGetfile
  280. frmGetFile.txtFileName.Text = ""
  281. frmGetFile.filFiles.Pattern = "*.txt"
  282. frmGetFile.filFiles.Refresh
  283.  
  284. End Sub
  285.  
  286. Sub mnuCopy_Click ()
  287.  
  288. 'Clear the clipboard
  289. Clipboard.Clear
  290.  
  291. 'Transfer to the clipboard
  292. Clipboard.SetText txtWorkArea.SelText
  293.  
  294. End Sub
  295.  
  296. Sub mnuCut_Click ()
  297.  
  298. 'Clear the clipboard
  299. Clipboard.Clear
  300.  
  301. 'Transfer to the clipboard
  302. Clipboard.SetText txtWorkArea.SelText
  303.  
  304. 'Delete the current selected aread
  305. txtWorkArea.SelText = ""
  306.  
  307. End Sub
  308.  
  309. Sub mnuDelete_Click ()
  310.  
  311. 'Delete selected area
  312. txtWorkArea.SelText = ""
  313.  
  314. End Sub
  315.  
  316. 'Copyright 1995 by Hitoshi Ozawa
  317. Sub mnuExit_Click ()
  318.   End
  319. End Sub
  320.  
  321. Sub mnuFDelete_Click ()
  322.  procDel
  323. End Sub
  324.  
  325. Sub mnuNew_Click ()
  326.  
  327. 'Clear text area
  328. txtWorkArea.Text = ""
  329. frmMain.Caption = ""
  330.  
  331. 'Reset filenames
  332. workfile.lopen = ""
  333. workfile.fopen = ""
  334.  
  335. procStatusBar
  336.  
  337. End Sub
  338.  
  339. 'Copyright 1995 by Hitoshi Ozawa
  340. Sub mnuOpen_Click ()
  341.  
  342. Dim retcode As Integer
  343.  
  344. 'Initialize file name to null
  345. workfile.lopen = ""
  346.  
  347. 'Display the frmGetFile as modal
  348. curForm = fGet
  349. frmGetFile.Show 1
  350. curForm = fMain
  351.  
  352. 'Change file name in status bar
  353. txtFname.Text = workfile.fopen
  354.  
  355. 'Change window caption
  356. If workfile.lopen = "" Then
  357.  frmMain.Caption = workfile.fopen
  358. Else
  359.  frmMain.Caption = workfile.lopen & "(" & workfile.fopen & ")"
  360. End If
  361.  
  362.  
  363. 'If not text file Execute file
  364. Select Case LCase$(Right$(frmGetFile.Tag, 3))
  365.  Case "exe"
  366.    retcode = Shell(frmGetFile.Tag, 1)
  367.  Case "com"
  368.    retcode = Shell(frmGetFile.Tag, 1)
  369.  Case "bat"
  370.    retcode = Shell(frmGetFile.Tag, 1)
  371.  Case "wri"
  372.    retcode = Shell("write.exe " & frmGetFile.Tag, 1)
  373.  Case Else   'if not any of above, treat at text file
  374.   'Get file number
  375.    FileNum = FreeFile
  376.  
  377.    'Open file for input
  378.    If Len(frmGetFile.Tag) Then
  379.      Open frmGetFile.Tag For Binary As FileNum    ' open file for input
  380.      txtWorkArea.Text = Input$(LOF(FileNum), FileNum)
  381.  
  382.      'Close file
  383.      Close FileNum
  384.  
  385.    End If
  386. End Select
  387.  
  388. End Sub
  389.  
  390. Sub mnuPaste_Click ()
  391.  
  392. 'Replace current selected area with content of clipboard
  393. txtWorkArea.SelText = Clipboard.GetText()
  394.  
  395. End Sub
  396.  
  397. 'Copyright 1995 by Hitoshi Ozawa
  398. Sub mnuSave_Click ()
  399.  
  400. Dim retcode As Integer
  401. Dim curpath As String
  402. Dim cnt
  403.  
  404. 'File name not entered - default to txtFname
  405. If frmGetFile.Tag = "" Then
  406.   workfile.lopen = ""
  407.   procMsave
  408.   Exit Sub
  409. End If
  410.  
  411. If workfile.fopen = "" Then
  412.  procSave
  413. Else
  414.  Select Case LCase$(Right$(frmGetFile.Tag, 3))
  415.   Case "exe"
  416.    retcode = Shell(frmGetFile.Tag, 1)
  417.   Case "com"
  418.    retcode = Shell(frmGetFile.Tag, 1)
  419.   Case "bat"
  420.    retcode = Shell(frmGetFile.Tag, 1)
  421.   Case "wri"
  422.    retcode = Shell("write.exe " & frmGetFile.Tag, 1)
  423.   Case Else   'if not any of above, treat at text file
  424.    procSave
  425.  End Select
  426. End If
  427.  
  428. 'Refresh file list
  429. frmGetFile.filFiles.Refresh
  430.  
  431. End Sub
  432.  
  433. Sub mnuTrash_Click ()
  434.   procTrash
  435. End Sub
  436.  
  437. Sub optID_Click ()
  438.  
  439. 'Recreate Combo IDs
  440. procGetID
  441.  
  442. End Sub
  443.  
  444. Sub optMemo_Click ()
  445.  
  446. 'Recreate Combo IDs
  447. procGetID
  448.  
  449. End Sub
  450.  
  451. Sub optName_Click ()
  452.  
  453. 'Recreate Combo IDs
  454. procGetID
  455.  
  456. End Sub
  457.  
  458. Sub procGetID ()
  459.  
  460. Dim Person As PersonInfo
  461. Dim FileNum As Integer
  462. Dim RecordLen As Long
  463. Dim CurrentRecord As Long
  464.  
  465. 'Clear Combo IDs
  466. cboID.Clear
  467.  
  468. 'Calculate length of record
  469. RecordLen = Len(Person)
  470.  
  471. 'Get a file number
  472. FileNum = FreeFile
  473.  
  474. On Error GoTo NOID
  475.  
  476. 'Open file from random access. Create file if doesn't exist
  477. Open "USERS.DAT" For Random As FileNum Len = RecordLen
  478.  
  479. CurrentRecord = 1
  480.  
  481. Do While Not EOF(FileNum)
  482.   Get #FileNum, CurrentRecord, Person
  483.   If optID.Value = True Then
  484.    cboID.AddItem Trim(Person.ID)
  485.   ElseIf optName.Value = True Then
  486.    cboID.AddItem Trim(Person.Name)
  487.   Else
  488.    cboID.AddItem Trim(Person.Memo)
  489.   End If
  490.   CurrentRecord = CurrentRecord + 1
  491. Loop
  492.  
  493. TotalRec = CurrentRecord
  494.  
  495. 'Close file
  496. Close FileNum
  497.  
  498. 'Set default to first ID
  499. cboID.ListIndex = 0
  500.  
  501. NOID:
  502. Exit Sub
  503.  
  504. End Sub
  505.  
  506. Sub procMsave ()
  507.  
  508. Dim retcode As Integer
  509. Dim curpath As String
  510. Dim cnt
  511. Dim savefile As String
  512.  
  513. 'Get file number
  514. FileNum = FreeFile
  515.  
  516. savefile = Trim(filedir.sdir) & txtFname.Text
  517.  
  518. 'Open file for input
  519. Open savefile For Output As FileNum
  520.  
  521. Print #FileNum, "TO:" & txtID.Text
  522. Print #FileNum, "SUB:" & txtSub.Text & Chr(10)
  523.  
  524. If txtFrom.Text <> "" Then
  525.  Print #FileNum, "FROM:" & txtFrom.Text
  526. End If
  527.  
  528. 'Output contents to text area
  529. Print #FileNum, txtWorkArea.Text
  530.  
  531. 'Close file
  532. Close FileNum
  533.  
  534. End Sub
  535.  
  536. Sub procSave ()
  537.  
  538. Dim retcode As Integer
  539. Dim curpath As String
  540. Dim cnt
  541.  
  542.  'Get file number
  543.  FileNum = FreeFile
  544.  
  545.  'Open file for input
  546.  Open frmGetFile.Tag For Output As FileNum
  547.  
  548.  'Output contents to text area
  549.  Print #FileNum, txtWorkArea.Text
  550.  
  551.  'Close file
  552.  Close FileNum
  553.  
  554. 'If it was a LZH file, update LZH file and delete text file
  555. If workfile.lopen <> "" Then
  556.  
  557.  'Save current path
  558.  curpath = CurDir
  559.  
  560.  'Reset buffer size
  561.  buffer = Space(szbuff)
  562.  
  563.  ChDrive Mid$(frmGetFile.Tag, 1, 2)
  564.  ChDir frmGetFile.filFiles.Path
  565.  
  566. 'Create LHA command
  567.  cmd = "a " & workfile.lopen & " " & workfile.fopen
  568.  
  569.  'Perform LHA operation
  570.  retcode = lha(cmd, buffer, szbuff)
  571.  
  572.  'Check for error
  573.  If retcode <> 0 Then
  574.   MsgBox ("Refresh error: " & retcode)
  575.   Exit Sub
  576.  End If
  577.  
  578.  'Delete extracted file
  579.  Kill workfile.fopen
  580.  
  581.  'Return to original drive
  582.  ChDrive Mid$(curpath, 1, 2)
  583.  
  584.  'Return to original path
  585.  ChDir curpath
  586.  
  587. End If
  588. End Sub
  589.  
  590. Sub procStatusBar ()
  591. Dim Person As PersonInfo
  592. Dim FileNum As Integer
  593. Dim RecordLen As Long
  594. Dim today
  595.  
  596. 'Calculate length of record
  597. RecordLen = Len(Person)
  598.  
  599. 'Get a file number
  600. FileNum = FreeFile
  601.  
  602. On Error GoTo STERRORID
  603.  
  604. 'Open file from random access. Create file if doesn't exist
  605. Open "USERS.DAT" For Random As FileNum Len = RecordLen
  606.  
  607. Get #FileNum, cboID.ListIndex + 1, Person
  608.  
  609. 'Update status bar
  610. txtID.Text = Trim(Person.ID)
  611. txtName.Text = Trim(Person.Name)
  612. txtMemo.Text = Trim(Person.Memo)
  613.  
  614. 'If there is no file name
  615. If workfile.fopen = "" Then
  616.  'Build filename using today's date
  617.  today = Now
  618.  txtFname.Text = Trim(Person.Fname) & Format(today, "yymmdd") & "." & Trim(Person.Fext)
  619.  
  620.  'Reset Header filename
  621.  frmMain.Caption = txtFname.Text
  622. End If
  623.  
  624. 'Close file
  625. Close FileNum
  626.  
  627. STERRORID:
  628. Exit Sub
  629.  
  630. End Sub
  631.  
  632. Sub procWriteID ()
  633. Dim Person As PersonInfo
  634. Dim FileNum As Integer
  635. Dim RecordLen As Long
  636. Dim pos
  637.  
  638. 'Calculate length of record
  639. RecordLen = Len(Person)
  640.  
  641. 'Get a file number
  642. FileNum = FreeFile
  643.  
  644. On Error GoTo WRERRORID
  645.  
  646. 'Open file from random access. Create file if doesn't exist
  647. Open "USERS.DAT" For Random As FileNum Len = RecordLen
  648.  
  649. 'Set record
  650. Person.ID = txtID.Text
  651. Person.Name = txtName.Text
  652. Person.Memo = txtMemo.Text
  653.  
  654. pos = InStr(txtFname.Text, ".")
  655. If pos = 0 Then
  656.  Person.Fname = txtFname.Text
  657.  Person.Fext = ""
  658. ElseIf pos < 2 Then
  659.  Person.Fname = ""
  660.  Person.Fext = Mid$(txtFname.Text, 2)
  661. ElseIf pos < 3 Then
  662.  Person.Fname = Left$(txtFname.Text, 1)
  663.  Person.Fext = Mid$(txtFname.Text, pos + 1)
  664. Else
  665.  Person.Fname = Left$(txtFname.Text, 2)
  666.  Person.Fext = Mid$(txtFname.Text, pos + 1)
  667. End If
  668.  
  669. 'Output record
  670. Put #FileNum, cboID.ListIndex + 1, Person
  671.  
  672. 'Close file
  673. Close FileNum
  674.  
  675. WRERRORID:
  676. Exit Sub
  677.  
  678. End Sub
  679.  
  680. Sub txtFname_LostFocus ()
  681.  
  682. 'Save changes
  683. procWriteID
  684.  
  685. End Sub
  686.  
  687. Sub txtMemo_LostFocus ()
  688.  
  689. 'Save changes
  690. procWriteID
  691.  
  692. End Sub
  693.  
  694.